" Vim with all enhancements
source $VIMRUNTIME/vimrc_example.vim

" Remap a few keys for Windows behavior
source $VIMRUNTIME/mswin.vim

filetype off
set shellslash
set rtp+=~/vimfiles/bundle/Vundle.vim
call vundle#begin('~/vimfiles/bundle')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" All of your Plugins must be added before the following line

"Plug 'scrooloose/nerdtree'
Plug 'mhinz/vim-startify'
Plug 'tpope/vim-fugitive'
Plug 'lfv88/vim-interestingwords'
Plug 'junegunn/vim-easy-align'
"Plug 'Valloric/YouCompleteMe'
Plug 'rkulla/pydiction'

call vundle#end()            " required

filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

" Use the internal diff if available.
" Otherwise use the special 'diffexpr' for Windows.

if &diffopt !~# 'internal'
  set diffexpr=MyDiff()
endif
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg1 = substitute(arg1, '!', '\!', 'g')
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg2 = substitute(arg2, '!', '\!', 'g')
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let arg3 = substitute(arg3, '!', '\!', 'g')
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      if empty(&shellxquote)
        let l:shxq_sav = ''
        set shellxquote&
      endif
      let cmd = '"' . $VIMRUNTIME . '\diff"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  let cmd = substitute(cmd, '!', '\!', 'g')
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  if exists('l:shxq_sav')
    let &shellxquote=l:shxq_sav
  endif
endfunction

" my settings
" 去除边框
set go=

" color
" TODO color desert
set t_Co=256

" 设置背景色，light/dark
set background=dark

" 语法高亮
syntax on

" mouse
set mouse=a

" 显示行号
set number

" 显示光标所在当前行的行号
"set relativenumber

" 高亮当前行
set cursorline

" 行宽
"set textwidth=80

" 自动拆行
set wrap

" 遇到指定符号才拆行
set linebreak

" 指定折行处与编辑窗口的右边缘之间空出的字符数
set wrapmargin=2

" 是否显示状态行
set laststatus=2

" 状态栏显示光标位置
set ruler

" 缩进: cindent (c style), smarindent (intelligence mode), autoindent (same as last line)
set cindent

" backspace
"set backspace=indent,eol,start

" replace tab with space
set expandtab "TODO 前面是否需要加冒号？ :set expandtab

" tab size = 4
set tabstop=4

" 缩进=4
set shiftwidth=4

" encoding
set encoding=utf-8

" 增量式搜索
set incsearch

" 高亮搜索
set hlsearch

" 括号匹配高亮
set showmatch

set ignorecase "忽略大小写
set smartcase "单大写字母单词，大小写敏感，其余情况，不敏感

" 检查文件类型
filetype on
filetype plugin on
filetype indent on

" 根据不同文件类型执行不同命令
"autocmd FileType python: setsmartindent

" 英文拼写检查
"set spell spelllang=en_us

" 不创建备份文件
"set nobackup

" 不创建交换文件
set noswapfile

" 保留撤销历史
set undofile
set mouse=a
" 备份文件、交换文件、操作历史文件位置
set backupdir=~/vimfiles/backup//
set directory=~/vimfiles/swp//
set undodir=~/vimfiles/undo//

" auto change working directory
set autochdir

" no bell when reach error
set noerrorbells

" screen flash when reach error
set visualbell

set history=1000

" keep watching on files
set autoread

" visualize white characters
set listchars=tab:»■,trail:■
set list

" tab complete
set wildmenu
set wildmode=longest:list,full

"nerdtree
"let mapleader = ","
"nnoremap <silent> <leader>n :NERDTreeToggle<CR>

" vim-interestingwords
"let g:interestingWordsGUIColors = ['#8CCBEA', '#A4E57E', '#FFDB72', '#FF7272', '#FFB3FF', '#9999FF']
"let g:interestingWordsTermColors = ['154', '121', '211', '137', '214', '222']
"let g:interestingWordsRandomiseColors = 1

" pydiction
let g:pydiction_location = '~/vimfiles/plugin/pydiction/complete-dict'
let g:pydiction_menu_height = 5
